/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.beautycenter.DAO;

import br.com.beautycenter.bean.Cargo;
import br.com.beautycenter.hibernateUtil.DaoBase;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Query;

/**
 *
 * @author Magelinha
 */
public class PersisteCargo extends DaoBase<Cargo> { 
    public List<Cargo> retornarCargos(){
        try {
            return findAll();
        } catch (Exception ex) {
            return new ArrayList<Cargo>();
        }
    }
      public Cargo retornarCargoPeloID(Cargo cargo){
        return getEntityManager().find(Cargo.class, cargo.getIdCargo());
    }
    
    public List<Cargo> retornarCargoPeloNome(Cargo cargo){
        Query query = getEntityManager().createQuery("FROM Cargo c WHERE c.nomeCargo LIKE :nome");
        query.setParameter("nome", "%"+cargo.getNomeCargo()+"%");

        try{
            return query.getResultList(); 
        }catch(Exception ex){
            return new ArrayList<Cargo>();
        }
    }
    public void salvar(Cargo cargo){
        save(cargo);
    }
    public void deletar(Cargo cargo){
        try{
            delete(cargo);
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
    
    public void atualizar(Cargo cargo){
        update(cargo);
    }
}



